package com.xuecheng.Controller;

import com.xuecheng.entity.Student;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("stu")
public class HelloController implements com.xuecheng.Controller.HelloControllerApi {

    /**
     * 测试无参数接口地址
     */
    @GetMapping("hello")
    public String hello() {
        return "hello";
    }
    /**
     * 测试 queryString 风格的参入参数
     * Get  http://ip:port/pro_root_path/stu?num=1111
     */
    @GetMapping
    public Student modifyStudentNum(@RequestParam("num") String num) {
        Student student = new Student(num, "xiaohong", 10, "parts");
        return student;
    }

    /**
     * 测试Restful风格的参入参数
     *  Get  http://ip:port/pro_root_path/stu/xiaoming
     */
    @GetMapping("{name}")
    public Student modifyStudentName(@PathVariable("name") String name) {
        Student student = new Student("002", name, 10, "parts");
        return student;
    }

    /**
     * 测试json格式的传入参数
     请求体传参(json格式的数据):
     Post  http://ip:port/pro_root_path/stu
     {
     “”：“”，
     “”：“”
     }

     */
    @PostMapping
    public Student modifyStudent(@RequestBody Student student) {
        student.setName("modifyName");
        return student;
    }


    /**
     * 测试 queryString 、Restful 和 json 格式的参数
     *   Put  http://ip:port/pro_root_path/stu/111?name=1111
     *     {
     *
     *
     *     }
     */
    @Override
    @PutMapping("{id}")
    public Student mofidyStudentBynNum(@PathVariable("id") String id,
                                       @RequestParam("name") String name,
                                       @RequestBody Student student) {
        student.setName(name);
        student.setStuNo(id);
        return student;
    }

}